from typing import List
class Solution:
    def canPlaceFlowers(self, flowerbed: List[int], n: int) -> bool:
        count, m, prev = 0, len(flowerbed), -1
        for i in range(m):
            if flowerbed[i] == 1:#遇到已经种植的花
                if prev < 0:
                    count += i // 2#最前端的花
                else:
                    count += (i - prev - 2) // 2#两朵花中间插入花
                prev = i

        if prev < 0:#没有遇到已经种植的花
            count += (m + 1) // 2
        else:#最后端花之后种植个数
            count += (m - prev - 1) // 2

        return count >= n#判断是否能够种植n朵花
flowerbed=[0,1,1,0,0,0,0,0,0,0,0,0,0,0]
solution=Solution()
print(solution.canPlaceFlowers(flowerbed,4))
